package com.controller;
import com.domain.User;
import com.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

@Controller
public class registerController {
    @Autowired
    UserMapper userMapper;

    @GetMapping(value = "/register")
    public String register(){return "comm/register";}
    @PostMapping(value = "toRegister")
    public String toRegister(User tUser, Model model) {
        try {
            int row = userMapper.insertUser(tUser);
            if (row > 0) {
                model.addAttribute("msg", "注册成功，请登录！");
                return "client/login";
            } else {
                model.addAttribute("error", "注册失败，服务器出错请联系服务员");

            }
        } catch (Exception ex) {
            model.addAttribute("error", "注册失败，已存在" + tUser.getUserName());
        }

        return "/register";
    }
}